<?php 

class Title_Ui{
	
	private $title;
	
	public function __construct(Title $title) {
		$this->title = $title;	
	}
	
	// Peut être appelé par Rating_Ui
	public function getTitleForList($ratingObj=false,$rating=false,$ratingicon=false,$date=false,$daterelative=false){
		
		if (! $ratingObj && isset($_SESSION['infosAuth']) && !empty($_SESSION['infosAuth'])){
			$ratingObj = Rating_Bd::getRating($_SESSION['infosAuth']->getIdUser(),$this->title->getIdTitle());
			$ratingObj = is_null($ratingObj->getIdRating()) ? null : $ratingObj ;
		
		}
		
		if (isset($ratingObj) && $ratingObj instanceof Rating){
			
			$rating = $rating == true ? $ratingObj->getScore() : "" ;
			
			if ($ratingicon == true && $rating != ""){
				if ($rating > 5)
					$rating = "<img src=\"../ui/images/aimemini.png\" alt=\"J'aime\"/>";
				else 
					if ($rating == 5)
						$rating = "<img src=\"../ui/images/neutremini.png\" alt=\"Sans avis\"/>";
					else 
						if ($rating >=0)
							$rating = "<img src=\"../ui/images/aimepasmini.png\" alt=\"J'aime pas\"/>";
						else 
							$rating ="?";
			}
			
	
			$date = $date == true ? Outils_Date::getFrDateFromSQL($ratingObj->getTime(),true,3,3) : "";
			$date = $daterelative && $date != "" ? Outils_Date::relativeTime(strtotime($ratingObj->getTime())) : $date; 
		} else {
			$rating = "";
			$date = "";	
		}
		
		$html = <<<EOT
			<div class="titleRat titleL">
			<input type="hidden" class="idTitle" value="{$this->title->getIdTitle()}"/>
				<span class="titleLartname">{$this->title->getArtist()} - {$this->title->getName()}</span><span class="titleLscore">{$rating}</span><span class="titleLratingdate">{$date}</span>
				<div class="clearer"></div>
			</div>
		
EOT;
		return $html;
		
	}
	
	
	
}

?>